package com.idelan.commonMessage.constant;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.annotation.Annotation;

/**
 * Created with IDEA
 * User gyli
 * date 2018/6/5
 */
public class NameValidatorClass implements ConstraintValidator<NameValidator, Object>, Annotation{
    private String values;

    @Override
    public Class<? extends Annotation> annotationType() {
        return null;
    }

    @Override
    public void initialize(NameValidator constraintAnnotation) {
        this.values = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        if (values.matches("^[a-zA-Z]/w{3,12}$")){
            return true;
        }
        return false;
    }
}
